#include "robot.h"
#include "ttf.h"
#include <stdio.h>
#include <stdlib.h>    //free使用的头文件
#include <string.h> //strdup
#include <curl/curl.h> //libcurl的头文件
#include "cJSON.h"

#define LINE_LEN 128

//输入，一次最多可转换128个字符
#define TEXT_LINE_LEN 128

//机器人回答的字符，一次最多可转换2048个字符
#define SPEAK_LINE_LEN 2048

//保存输入字符串的缓存区
char speak_line[SPEAK_LINE_LEN];

//保存输入字符串的缓存区
char line[LINE_LEN];


//保存输入字符串的缓存区
char text_line[TEXT_LINE_LEN];



int main()
{
    char* token = get_token("ohZQGov7stmOduZmNp6aGGI2", "Em0SA1AeeATBLs3AffCDgRHXh3vyWNi5");
    char *apikey = "abffa9d2e6d94ceaa26424b2eb5f62c9";
    if(NULL == token)
    {
        return EXIT_FAILURE;
    }

    //从标准输入读取一行字符
    while(fgets(line, TEXT_LINE_LEN, stdin) != NULL)
    {

         //构造请求报文讲话的
        char* request = robot_make_reqeire(apikey, line);
        if(request ==NULL)
        {
            continue;
        }

        //将请求报文发送给图灵机器人
        char* response_1 = robot_send_request(request);
        //printf("%s\n", response_1);
        char* answer = robot_trans_response(response_1);
        text2speech(token, answer);
    }
    free(token);
    return 0;

}